var touserid = pageParam['user_id'];
_log(touserid)
var lon = getCookie('lon') || 113.320234;
var lat = getCookie('lat') || 23.022241;
var view = new Vue({
    el: '#view',
    data: {
        imgurl: imgurl,
        data: {},
        myuserid: myuserid,
        // isRenZheng: 0,
        imgList: [], // 相册
        ffList: [], // 评价列表
        uid: pageParam['user_id'],
        pjStr: {}, // 评价id
        pjType: 0, // 是否显示评价模态框
    },
    methods: {
        // 复制
        copyTxt: function (text) {
            copyTxt(text)
        },
        _url: function (param, url) {
            _url(param, url);
        },
        // 图片自适应
        imgCss: function (url, event) {
            var e = event.currentTarget;
            imgCss(url, function (w, h) {
                if (w < h) {
                    $(e).parent().addClass('img-w').removeClass('img-h');
                }
            })
        },
        // 评价选择
        greet: function (id, index) {
            var _this = this;
            if (_this.uid == _this.myuserid) {
                _msg('不能对自己评价');
                return;
            }
            // 判断是否有评价权限
            _ajax('Home/Dymanic/checkeva', function (ret, err) {
                _log(JSON.stringify(ret));
                _log(JSON.stringify(err));
                if (ret && ret.code == 200) {

                    var status = _this.ffList[index].select;
                    _this.ffList[index].select = status == 0 ? 1 : 0;
                    _this.ffList[index].num = status == 0 ? parseInt(_this.ffList[index].num) +
                        1 : _this.ffList[index].num - 1;
                    _this.pjStr[id] = _this.ffList[index].select;

                } else {
                    _msg(ret.msg);
                }
            }, {
                user_id: myuserid,
                main_id: _this.uid,
            })
        }
    }
})
judgeLogin()
// getPhone();
// getReal();
getInfo();

getPing();
getPj();

// 获取用户信息
function getInfo() {
    _getUser(function (ret) {
        view.data = ret.result;
        setCookie('myyue', ret.result.volley);
        xiangce();
    }, touserid, myuserid)
}

// // 获取认证状态
// function getReal() {
//     _ajax('Home/User/isrenzheng', function (ret, err) {
//         _log(JSON.stringify(ret))
//         _log(JSON.stringify(err))
//         if (ret && ret.code == 200) {
//             view.isRenZheng = ret.result.is_identity_authentication;
//         }
//     }, {
//         user_id: touserid,
//     })
// }


// 获取手机号
function getPhone() {
    _ajax('Home/User/getphone', function (ret, err) {
        _log(JSON.stringify(ret))
        _log(JSON.stringify(err))
        if (ret && ret.code == 201) {
            if (ret.msg == '请充值会员') {
                _alert('请先充值会员', function () {
                    _url({}, 'frame4');
                })
            } else {
                _alert('今天你访问超额了', function () {
                    _closeToWin();
                })
            }
        }
    }, {
        user_id: myuserid,
    })
}

// 用户相册
function xiangce() {
    _ajax('user_img_list.php', function (ret, err) {
        _log(JSON.stringify(ret));
        _log(JSON.stringify(err));
        if (ret && ret.code == 200) {
            view.imgList = ret.result;
        }
    }, {
        user_id: touserid,
        to_user: myuserid,
    })
}

// 关注
function guanzhu() {
    var url = view.data.love == 0 ? 'attention_user.php' : 'cancel_attention.php';
    var msg = view.data.love == 0 ? '关注成功' : '取消关注';
    _ajax(url, function (ret, err) {
        _log(JSON.stringify(ret));
        if (ret && ret.code == 200) {
            _msg(msg);
            pushMsg(uid);
            view.data.love = view.data.love == 0 ? 1 : 0;
        }
    }, {
        user_id: myuserid,
        to_user: touserid,
    })
}

// 获取用户评价
function getPing() {
    _ajax('Home/Dymanic/evalist', function (ret, err) {
        _log(JSON.stringify(ret))
        _log(JSON.stringify(err))
    }, {
        main_id: touserid,
    })
}

// 更多
$('#js-winmore').on('click', function () {
    var buttons = ['拉黑(屏蔽双方)', '匿名举报'];
    _action('', buttons, function (index) {
        if (index != (buttons.length + 1)) {
            if (index == 1) {
                // 拉黑
                _alert('拉黑后你们将无法看到对方和对方的动态，确定吗？', function(){

                    _ajax('add_black_list.php', function (ret, err) {
                        _log(JSON.stringify(ret))
                        var msg = ret.code == 200 ? '拉黑成功' : '拉黑失败';
                        _msg(msg);
                    }, {
                        to_user: touserid,
                        user_id: myuserid,
                    })
                })
            } else if (index == 2) {
                // 举报
                _url({
                    url: 'frame0/ju_bao_frame',
                    title: '匿名举报',
                    uid: touserid
                })

            }
        }
    })
})

// 私聊
function openChat() {
    // _url({
    //     txt: view.data.name,
    //     touserid: view.data.id,
    //     url: 'frame0/liaotian',
    //     title: '与' + view.data.name + '的聊天'
    // })
    judgeQx(function () {
        view.data.link = 1;
        _url({
            txt: view.data.name,
            touserid: view.data.id,
            url: 'frame0/liaotian',
            title: '与' + view.data.name + '的聊天'
        })
    })
}

// 社交账号
function showLink() {
    // _msg('已获取联系方式');
    judgeQx(function () {
        view.data.link = 1;
        var text = (view.data.wxcount || view.data.qq) ? '已获取联系方式' : '对方未填写联系方式';
        _msg(text);
    })
}

// 判断权限
function judgeQx(callback) {
    _ajax('home/user/vipsee', function (ret, err) {
        _log(JSON.stringify(ret));
        _log(JSON.stringify(err));
        if (ret.code == 200) {
            if (view.data.sex == '男') {
                callback();
            } else {
                var obj = {
                    msg: '您今日可私聊并看查他人联系方式次数还剩余' + ret.num + '次,请确定以下操作',
                };
                _confirm(obj, function (bIndex) {
                    if (bIndex == 1) {
                        _ajax('home/user/getlink', function (rets, errs) {
                            _log(JSON.stringify(rets));
                            _log(JSON.stringify(errs));
                            if (rets && rets.code == 200) {
                                callback();
                            } else {
                                _msg(rets.msg);
                            }
                        }, {
                            user_id: myuserid,
                            to_user: touserid,
                        })
                    }
                })
            }
        } else if (ret.code == 201) {
            _alert('您还未认证，请先去认证', function () {
                _url({ url: 'frame4/authentication_frame', title: '认证身份' });
            })
        } else if (ret.code == 202) {
            _alert('您还不是会员呢~，前去购买', function () {
                _url({ url: 'frame4', title: '开通会员' })
            })
        } else if (ret.code == 205) {
            callback();
        } else if (ret.code == 220 && ret.money) {
            var obj = {
                msg: '您今日会员特权使用次数已用完,您可以支付' + ret.money + '查看该用户全部信息。请确定以下操作',
                btn: ['购买', '取消'],
            };
            _confirm(obj, function (bIndex) {
                if (bIndex == 1) {
                    _ajax('home/user/buylian', function (rets, errs) {
                        _log(JSON.stringify(rets));
                        _log(JSON.stringify(errs));
                        pushMsg(myuserid); // 给自己推
                        if (rets && rets.code == 200) {
                            callback();
                        } else {
                            _msg(rets.msg);
                        }
                    }, {
                        user_id: myuserid,
                        to_user: touserid,
                    })
                }
            })
        }
    }, {
        user_id: myuserid,
        to_user: touserid,
    })
}

// 获取评价列表
function getPj() {
    _ajax('Home/Dymanic/evalist', function (ret, err) {
        _log(JSON.stringify(ret));
        _log(JSON.stringify(err));
        if (ret && ret.code == 200) {
            view.ffList = ret.data;
            for (var i = 0, len = ret.data.length; i < len; i++) {
                view.ffList[i].select = 0;
            }
        }
    }, {
        main_id: view.uid,
    })
}

// 匿名评价
function sendPj() {
    var str = [];
    for (var k in view.pjStr) {
        if (view.pjStr[k] == 1) {
            str.push(k);
        }
    }
    if (str.length == 0) {
        _msg('评价选项不能为空');
        return;
    }
    _ajax('Home/Dymanic/evaluate', function (ret, err) {
        _log(JSON.stringify(ret));
        _log(JSON.stringify(err));
        _msg(ret.msg);
        pushMsg(view.uid);
    }, {
        userid: myuserid,
        main_id: view.uid,
        evaluate: str,
    })
}

// 显示或隐藏 评价模态框
function showEval(type) {
    view.pjType = type;
}


// 解锁相册
function authimg() {
    _ajax('home/user/vipimg', function (ret, err) {
        _log(JSON.stringify(ret));
        _log(JSON.stringify(err));
        if (ret.code == 200) {
            var obj = {
                title: '解锁该用户的付费相册',
                msg: '今日您剩余' + ret.num + '次查看他人付费相册。解锁后，您可以永久免费查看该用户的相册。请确认操作',
            };
            _confirm(obj, function (bIndex) {
                if (bIndex == 1) {
                    _ajax('home/user/Incxiang', function (rets, errs) {
                        _log(JSON.stringify(rets));
                        _log(JSON.stringify(errs));
                        if (rets && rets.code == 200) {
                            view.data.state = 2;
                        } else {
                            _msg(rets.msg);
                        }
                    }, {
                        user_id: myuserid,
                        to_user: touserid,
                    })
                }
            })
        } else if (ret.code == 201) {
            _alert('您还未认证，请先去认证', function () {
                _url({
                    url: 'frame4/authentication_frame',
                    title: '认证身份'
                });
            })
        } else if (ret.code == 202) {
            var buttons = ['付费查看' + feeObj.money + 'USDT', '购买会员'];
            _action('解锁该用户的付费相册', buttons, function (bIndex) {
                if (bIndex == 1) {
                    _ajax('Home/User/authimg', function (rets, errs) {
                        _log(JSON.stringify(rets));
                        _log(JSON.stringify(errs));
                        if (rets && rets.code == 200) {
                            view.data.state = 2;
                            pushMsg(touserid);
                        } else {
                            _msg(rets.msg);
                            if (rets.msg.indexOf('不足') != -1) {
                                showDetail('frame4/show_chong');
                            }
                        }
                    }, {
                        user_id: touserid,
                        to_user: myuserid,
                    })
                } else if (bIndex == 2) {
                    _url({ url: 'frame4', title: '开通会员' })
                }
            })
        } else if (ret.code == 204) {
            var obj = {
                title: '解锁该用户的付费相册',
                msg: '您今日免费查看他人付费相册次数已用完，但你可以付费查看~解锁后，您可以永久免费查看该用户的相册。请确认您的操作',
                btn: ['付费查看' + feeObj.money + 'USDT', '取消'],
            };
            _confirm(obj, function (bIndex) {
                if (bIndex == 1) {
                    _ajax('Home/User/authimg', function (rets, errs) {
                        _log(JSON.stringify(rets));
                        _log(JSON.stringify(errs));
                        if (rets && rets.code == 200) {
                            view.data.state = 2;
                            pushMsg(touserid);
                        } else {
                            _msg(rets.msg);
                            if (rets.msg.indexOf('不足') != -1) {
                                showDetail('frame4/show_chong');
                            }
                        }
                    }, {
                        user_id: touserid,
                        to_user: myuserid,
                    })

                }
            })
        } else if (ret.code == 205) {
            view.data.img_auth = 0;
        } else {
            _msg(ret.msg);
        }
    }, {
        user_id: myuserid,
        to_user: touserid,
    })
}

// 申请查看
function apply() {
   
    var obj = {
        title: '向该用户申请查看资料',
        msg: '申请时，需要你的一张照片给对方查看',
        buttons: ['发送照片', '取消'],
    };
    _confirm(obj, function (bIndex) {
        if (bIndex == 1) {
            $('#apply-pic').click();
        }
    })
}

// 提交图片
$('#apply-pic').on('change', function () {
    _loading();
    var image = this.files[0];
    _upImg(image, function (u) {
        _ajax('Home/User/requestimg', function (rets) {
            _loadingClose();
            _msg(rets.msg)
        }, {
            user_id: touserid,
            to_user: myuserid,
            pic: u
        })
    })
})